package com.burns.flash.javafx.stage;/**
 * Created by burns.
 *
 * @author <a href="http://www.esoon-soft.com/">burns</a>
 * @date 2022/02/21 13:40
 */

import javafx.application.Application;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;

import static javafx.scene.input.KeyCode.*;

public class StageKeyBoardEvents extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, (event) -> {
            System.out.println("Key pressed: " + event.toString());

            switch (event.getCode()) {
                case ESCAPE: { // 27 = ESC key
                    primaryStage.close();
                    break;
                }
                case ENTER: { // 10 = Return
                    primaryStage.setWidth(primaryStage.getWidth() * 2);
                }
                default: {
                    System.out.println("Unrecognized key");
                }
            }
        });
        primaryStage.show();
    }
}
